package com.wangyu.springsecuritydemo.repository.primary;

import com.wangyu.springsecuritydemo.entity.primary.UserEntity;
import com.wangyu.springsecuritydemo.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * 用户数据持久层
 *
 * @Author wangyu
 * @Date 2019/2/18 22:50
 * @Version 1.0
 */
public interface UserRepository extends BaseRepository<UserEntity> {

  /**
   * 根据用户名查询
   *
   * @param username 用户名
   */
  UserEntity findByUserName(String username);

  /**
   * 插入用户角色关联信息
   *
   * @param userId 用户ID
   * @param roleId 角色ID
   */
  @Modifying
  @Query(value = "insert into sys_role_user(user_id,role_id) value (:userId,:roleId)", nativeQuery = true)
  void insertRoles(@Param("userId") String userId, @Param("roleId") String roleId);
}
